/* filter.c */

/******************************/
/* AUDIO-FILTERING            */
/* for Secure Phone           */
/* Copyright (C) 2003 by NAH6 */
/******************************/

/*
 * The functionality of this filter is based on resample.c and related files
 * which contained the following original copyright notices:
 */

/*
 * FILE: resample.c
 *   BY: Julius Smith (at CCRMA, Stanford U)
 * C BY: translated from SAIL to C by Christopher Lee Fraley
 *          (cf0v@spice.cs.cmu.edu or @andrew.cmu.edu)
 * DATE: 7-JUN-88
 *
 * HACKED: Lance Norskog, Dec. 28, 1991, to make sealed resampler for SoundKit
 */

/*
 *      The original version of this program in SAIL may be found in:
 *      /../s/usr/mhs/resample  or  /../x/usr/rbd/src/resample
 *
 *      Implement sampling rate conversions by (almost) arbitrary factors.
 *      Based on SRCONV.SAI[SYS,MUS] with new algorithm by JOS&PG.
 *      The program internally uses 16-bit data and 16-bit filter
 *      coefficients.
 *
 *      Reference: "A Flexible Sampling-Rate Conversion Method,"
 *      J. O. Smith and P. Gossett, ICASSP, San Diego, 1984, Pgs 19.4.
 */

/*
 * July 5, 1991
 * Copyright 1991 Lance Norskog And Sundry Contributors
 * This source code is freely redistributable and may be used for
 * any purpose.  This copyright notice must be maintained. 
 * Lance Norskog And Sundry Contributors are not responsible for 
 * the consequences of using this software.
 */


/*------------*/
/*  INCLUDES  */
/*------------*/

#include <stddef.h>
#include <memory.h>

#include "filter.h"

/*-----------*/
/*  DEFINES  */
/*-----------*/

#define K_FILTER_XOFF_11_8      17
#define K_FILTER_DHB_11_8       23831
#define K_FILTER_LPSCL_11_8     9071
#define K_FILTER_IPOL_11_8      1

#define K_FILTER_XOFF_8_11      15
#define K_FILTER_LPSCL_8_11     12471
#define K_FILTER_IPOL_8_11      1

/*--*/

#define K_FILTER_XOFF_16_8      0
#define K_FILTER_DHB_16_8       0
#define K_FILTER_LPSCL_16_8     0
#define K_FILTER_IPOL_16_8      0

#define K_FILTER_XOFF_8_16      0
#define K_FILTER_LPSCL_8_16     0
#define K_FILTER_IPOL_8_16      0

/*--*/

#define K_FILTER_XOFF_22_8      17
#define K_FILTER_DHB_22_8       11916
#define K_FILTER_LPSCL_22_8     4534
#define K_FILTER_IPOL_22_8      1

#define K_FILTER_XOFF_8_22      12
#define K_FILTER_LPSCL_8_22     12471
#define K_FILTER_IPOL_8_22      1

/*--*/

#define K_FILTER_XOFF_24_8      0
#define K_FILTER_DHB_24_8       0
#define K_FILTER_LPSCL_24_8     0
#define K_FILTER_IPOL_24_8      0

#define K_FILTER_XOFF_8_24      0
#define K_FILTER_LPSCL_8_24     0
#define K_FILTER_IPOL_8_24      0

/*--*/

#define K_FILTER_XOFF_32_8      0
#define K_FILTER_DHB_32_8       0
#define K_FILTER_LPSCL_32_8     0
#define K_FILTER_IPOL_32_8      0

#define K_FILTER_XOFF_8_32      0
#define K_FILTER_LPSCL_8_32     0
#define K_FILTER_IPOL_8_32      0

/*--*/

#define K_FILTER_XOFF_44_8      17
#define K_FILTER_DHB_44_8       5944
#define K_FILTER_LPSCL_44_8     2262
#define K_FILTER_IPOL_44_8      1

#define K_FILTER_XOFF_8_44      11
#define K_FILTER_LPSCL_8_44     12471
#define K_FILTER_IPOL_8_44      1

/*--*/

#define K_FILTER_XOFF_48_8      0
#define K_FILTER_DHB_48_8       0
#define K_FILTER_LPSCL_48_8     0
#define K_FILTER_IPOL_48_8      0

#define K_FILTER_XOFF_8_48      0
#define K_FILTER_LPSCL_8_48     0
#define K_FILTER_IPOL_8_48      0

/*----*/

#define K_FILTER_NA              7
#define K_FILTER_NP             15
#define K_FILTER_NPC           256
#define K_FILTER_NHG             2
#define K_FILTER_NHXN           14
#define K_FILTER_NLPSCL         13
#define K_FILTER_AMASK        0x7F
#define K_FILTER_PMASK      0x7FFF

#define K_FILTER_IMPTBL1LEN   1536
#define K_FILTER_IMPTBL2LEN   3072

/* Description of constants:
 *
 * Na - is the number of bits devoted to linear interpolation of the
 *    filter coefficients.
 * Np - is Na + Nhc, the number of bits to the right of the binary point
 *    in the integer "time" variable. To the left of the point, it indexes
 *    the input array (X), and to the right, it is interpreted as a number
 *    between 0 and 1 sample of the input X.  Np must be less than 16 in
 *    this implementation.
 *
 * Npc - is the number of look-up values available for the lowpass filter
 *    between the beginning of its impulse response and the "cutoff time"
 *    of the filter.  The cutoff time is defined as the reciprocal of the
 *    lowpass-filter cut off frequence in Hz.  For example, if the
 *    lowpass filter were a sinc function, Npc would be the index of the
 *    impulse-response lookup-table corresponding to the first zero-
 *    crossing of the sinc function.  (The inverse first zero-crossing
 *    time of a sinc function equals its nominal cutoff frequency in Hz.)
 *    Npc must be a power of 2 due to the details of the current
 *    implementation. The default value of 512 is sufficiently high that
 *    using linear interpolation to fill in between the table entries
 *    gives approximately 16-bit accuracy in filter coefficients.
 *
 * Nhg - is the number of guard bits in mpy-add accumulation (equal to Nh-Nhxn)
 *
 * Nhxn - is the number of bits to right shift after multiplying each input
 *    sample times a filter coefficient. It can be as great as Nh and as
 *    small as 0. Nhxn = Nh-2 gives 2 guard bits in the multiply-add
 *    accumulation.  If Nhxn=0, the accumulation will soon overflow 32 bits.
 *
 * NLpScl - is the number of bits allocated to the unity-gain normalization
 *    factor.  The output of the lowpass filter is multiplied by LpScl and
 *    then right-shifted NLpScl bits. To avoid overflow, we must have
 *    Nb+Nhg+NLpScl < 32.
/*    Used to be 13128, but using factor .95 to reduce clipping.
 */

/*--------------*/
/*  PROTOTYPES  */
/*--------------*/

static signed long filter__convert_updown (const signed short *p,            \
                                           signed short ph, signed char inc, \
                                           unsigned long dhb,                \
                                           unsigned char ipol);
static signed long filter__convert_up (const signed short *p, signed short ph, \
                                       signed char inc, unsigned char ipol);
/*-------------*/
/*  VARIABLEN  */
/*-------------*/

const unsigned short filter_samplerate[K_FILTER_SAMPLERATES] =
{
  8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
};

const unsigned short filter_chunklen[K_FILTER_SAMPLERATES] =
{
  K_FILTER_CHUNKSIZE_8K,  K_FILTER_CHUNKSIZE_11K, K_FILTER_CHUNKSIZE_16K,
  K_FILTER_CHUNKSIZE_22K, K_FILTER_CHUNKSIZE_24K, K_FILTER_CHUNKSIZE_32K,
  K_FILTER_CHUNKSIZE_44K, K_FILTER_CHUNKSIZE_48K
};

/*====*/

static const unsigned char filter__xto8_xoff[K_FILTER_SAMPLERATES - 1] =
{
  K_FILTER_XOFF_11_8, K_FILTER_XOFF_16_8, K_FILTER_XOFF_22_8,
  K_FILTER_XOFF_24_8, K_FILTER_XOFF_32_8, K_FILTER_XOFF_44_8,
  K_FILTER_XOFF_48_8
};

static const unsigned short filter__xto8_dhb[K_FILTER_SAMPLERATES - 1] =
{
  K_FILTER_DHB_11_8, K_FILTER_DHB_16_8, K_FILTER_DHB_22_8,
  K_FILTER_DHB_24_8, K_FILTER_DHB_32_8, K_FILTER_DHB_44_8,
  K_FILTER_DHB_48_8
};

static const unsigned short filter__xto8_lpscl[K_FILTER_SAMPLERATES - 1] =
{
  K_FILTER_LPSCL_11_8, K_FILTER_LPSCL_16_8, K_FILTER_LPSCL_22_8,
  K_FILTER_LPSCL_24_8, K_FILTER_LPSCL_32_8, K_FILTER_LPSCL_44_8,
  K_FILTER_LPSCL_48_8
};

static const unsigned char filter__xto8_ipol[K_FILTER_SAMPLERATES - 1] =
{
  K_FILTER_IPOL_11_8, K_FILTER_IPOL_16_8, K_FILTER_IPOL_22_8,
  K_FILTER_IPOL_24_8, K_FILTER_IPOL_32_8, K_FILTER_IPOL_44_8,
  K_FILTER_IPOL_48_8
};

/*--*/

static const unsigned char filter__8tox_xoff[K_FILTER_SAMPLERATES - 1] =
{
  K_FILTER_XOFF_8_11, K_FILTER_XOFF_8_16, K_FILTER_XOFF_8_22,
  K_FILTER_XOFF_8_24, K_FILTER_XOFF_8_32, K_FILTER_XOFF_8_44,
  K_FILTER_XOFF_8_48
};

static const unsigned short filter__8tox_lpscl[K_FILTER_SAMPLERATES - 1] =
{
  K_FILTER_LPSCL_8_11, K_FILTER_LPSCL_8_16, K_FILTER_LPSCL_8_22,
  K_FILTER_LPSCL_8_24, K_FILTER_LPSCL_8_32, K_FILTER_LPSCL_8_44,
  K_FILTER_LPSCL_8_48
};

static const unsigned char filter__8tox_ipol[K_FILTER_SAMPLERATES - 1] =
{
  K_FILTER_IPOL_8_11, K_FILTER_IPOL_8_16, K_FILTER_IPOL_8_22,
  K_FILTER_IPOL_8_24, K_FILTER_IPOL_8_32, K_FILTER_IPOL_8_44,
  K_FILTER_IPOL_8_48
};

/*----*/

static const unsigned short filter__imptbl1[K_FILTER_IMPTBL1LEN] = \
{
  0x7FFF,0x7FFE,0x7FFC,0x7FF8,0x7FF3,0x7FED,0x7FE5,0x7FDB,
  0x7FD1,0x7FC4,0x7FB7,0x7FA7,0x7F97,0x7F85,0x7F71,0x7F5C,
  0x7F46,0x7F2E,0x7F15,0x7EFA,0x7EDE,0x7EC0,0x7EA1,0x7E81,
  0x7E5F,0x7E3C,0x7E17,0x7DF1,0x7DCA,0x7DA1,0x7D77,0x7D4B,
  0x7D1E,0x7CF0,0x7CC0,0x7C8F,0x7C5C,0x7C28,0x7BF3,0x7BBC,
  0x7B84,0x7B4B,0x7B10,0x7AD4,0x7A97,0x7A58,0x7A18,0x79D7,
  0x7994,0x7950,0x790B,0x78C4,0x787D,0x7833,0x77E9,0x779D,
  0x7750,0x7702,0x76B3,0x7662,0x7610,0x75BD,0x7569,0x7513,
  0x74BC,0x7464,0x740B,0x73B1,0x7355,0x72F9,0x729B,0x723C,
  0x71DC,0x717A,0x7118,0x70B4,0x7050,0x6FEA,0x6F83,0x6F1B,
  0x6EB2,0x6E48,0x6DDD,0x6D71,0x6D04,0x6C95,0x6C26,0x6BB6,
  0x6B45,0x6AD2,0x6A5F,0x69EB,0x6976,0x68FF,0x6888,0x6810,
  0x6797,0x671E,0x66A3,0x6627,0x65AB,0x652D,0x64AF,0x6430,
  0x63B0,0x632F,0x62AE,0x622B,0x61A8,0x6124,0x609F,0x601A,
  0x5F93,0x5F0C,0x5E85,0x5DFC,0x5D73,0x5CE9,0x5C5F,0x5BD3,
  0x5B48,0x5ABB,0x5A2E,0x59A0,0x5912,0x5883,0x57F3,0x5763,
  0x56D2,0x5641,0x55AF,0x551D,0x548A,0x53F6,0x5362,0x52CE,
  0x5239,0x51A4,0x510E,0x5078,0x4FE1,0x4F4A,0x4EB2,0x4E1B,
  0x4D82,0x4CEA,0x4C51,0x4BB7,0x4B1E,0x4A84,0x49EA,0x494F,
  0x48B4,0x4819,0x477E,0x46E2,0x4646,0x45AA,0x450E,0x4471,
  0x43D5,0x4338,0x429B,0x41FE,0x4161,0x40C3,0x4026,0x3F88,
  0x3EEA,0x3E4D,0x3DAF,0x3D11,0x3C73,0x3BD5,0x3B37,0x3A99,
  0x39FB,0x395D,0x38BF,0x3821,0x3784,0x36E6,0x3648,0x35AB,
  0x350D,0x3470,0x33D2,0x3335,0x3298,0x31FB,0x315F,0x30C2,
  0x3026,0x2F8A,0x2EEE,0x2E52,0x2DB7,0x2D1C,0x2C81,0x2BE6,
  0x2B4C,0x2AB1,0x2A18,0x297E,0x28E5,0x284C,0x27B4,0x271B,
  0x2684,0x25EC,0x2555,0x24BF,0x2428,0x2392,0x22FD,0x2268,
  0x21D3,0x213F,0x20AC,0x2018,0x1F86,0x1EF4,0x1E62,0x1DD1,
  0x1D40,0x1CB0,0x1C20,0x1B91,0x1B02,0x1A75,0x19E7,0x195A,
  0x18CE,0x1842,0x17B7,0x172D,0x16A3,0x161A,0x1591,0x1509,
  0x1482,0x13FB,0x1375,0x12F0,0x126C,0x11E8,0x1164,0x10E2,
  0x1060,0x0FDF,0x0F5F,0x0EDF,0x0E60,0x0DE2,0x0D65,0x0CE8,
  0x0C6C,0x0BF1,0x0B77,0x0AFD,0x0A84,0x0A0C,0x0995,0x091F,
  0x08A9,0x0835,0x07C1,0x074E,0x06DB,0x066A,0x05F9,0x058A,
  0x051B,0x04AD,0x0440,0x03D3,0x0368,0x02FD,0x0294,0x022B,
  0x01C3,0x015C,0x00F6,0x0091,0x002C,0xFFCA,0xFF67,0xFF06,
  0xFEA5,0xFE45,0xFDE7,0xFD89,0xFD2C,0xFCD0,0xFC74,0xFC1A,
  0xFBC1,0xFB69,0xFB11,0xFABB,0xFA65,0xFA11,0xF9BD,0xF96B,
  0xF919,0xF8C8,0xF878,0xF82A,0xF7DC,0xF78F,0xF743,0xF6F8,
  0xF6AE,0xF665,0xF61D,0xF5D5,0xF58F,0xF54A,0xF506,0xF4C2,
  0xF480,0xF43F,0xF3FE,0xF3BF,0xF380,0xF343,0xF306,0xF2CB,
  0xF290,0xF256,0xF21E,0xF1E6,0xF1AF,0xF179,0xF144,0xF110,
  0xF0DD,0xF0AB,0xF07A,0xF04A,0xF01B,0xEFEC,0xEFBF,0xEF93,
  0xEF67,0xEF3D,0xEF13,0xEEEA,0xEEC3,0xEE9C,0xEE76,0xEE51,
  0xEE2D,0xEE09,0xEDE7,0xEDC6,0xEDA5,0xED86,0xED67,0xED49,
  0xED2C,0xED10,0xECF5,0xECDB,0xECC2,0xECA9,0xEC92,0xEC7B,
  0xEC65,0xEC50,0xEC3C,0xEC28,0xEC16,0xEC04,0xEBF3,0xEBE3,
  0xEBD4,0xEBC6,0xEBB8,0xEBAB,0xEB9F,0xEB94,0xEB8A,0xEB80,
  0xEB77,0xEB6F,0xEB68,0xEB62,0xEB5C,0xEB57,0xEB53,0xEB4F,
  0xEB4D,0xEB4B,0xEB49,0xEB49,0xEB49,0xEB4A,0xEB4C,0xEB4E,
  0xEB51,0xEB55,0xEB59,0xEB5E,0xEB64,0xEB6A,0xEB71,0xEB79,
  0xEB82,0xEB8B,0xEB94,0xEB9F,0xEBAA,0xEBB5,0xEBC1,0xEBCE,
  0xEBDB,0xEBE9,0xEBF8,0xEC07,0xEC17,0xEC27,0xEC38,0xEC49,
  0xEC5B,0xEC6E,0xEC81,0xEC94,0xECA8,0xECBD,0xECD2,0xECE7,
  0xECFD,0xED14,0xED2B,0xED43,0xED5A,0xED73,0xED8C,0xEDA5,
  0xEDBF,0xEDD9,0xEDF4,0xEE0F,0xEE2A,0xEE46,0xEE62,0xEE7F,
  0xEE9C,0xEEBA,0xEED7,0xEEF5,0xEF14,0xEF33,0xEF52,0xEF72,
  0xEF92,0xEFB2,0xEFD2,0xEFF3,0xF014,0xF036,0xF057,0xF079,
  0xF09C,0xF0BE,0xF0E1,0xF104,0xF127,0xF14B,0xF16F,0xF193,
  0xF1B7,0xF1DC,0xF200,0xF225,0xF24A,0xF270,0xF295,0xF2BB,
  0xF2E0,0xF306,0xF32D,0xF353,0xF379,0xF3A0,0xF3C7,0xF3ED,
  0xF414,0xF43B,0xF463,0xF48A,0xF4B1,0xF4D9,0xF500,0xF528,
  0xF550,0xF577,0xF59F,0xF5C7,0xF5EF,0xF617,0xF63F,0xF667,
  0xF68F,0xF6B7,0xF6DF,0xF707,0xF730,0xF758,0xF780,0xF7A8,
  0xF7D0,0xF7F8,0xF820,0xF848,0xF870,0xF898,0xF8C0,0xF8E7,
  0xF90F,0xF937,0xF95E,0xF986,0xF9AD,0xF9D5,0xF9FC,0xFA23,
  0xFA4A,0xFA71,0xFA98,0xFABF,0xFAE6,0xFB0C,0xFB32,0xFB59,
  0xFB7F,0xFBA5,0xFBCB,0xFBF0,0xFC16,0xFC3B,0xFC61,0xFC86,
  0xFCAA,0xFCCF,0xFCF4,0xFD18,0xFD3C,0xFD60,0xFD84,0xFDA8,
  0xFDCB,0xFDEE,0xFE12,0xFE34,0xFE57,0xFE79,0xFE9C,0xFEBE,
  0xFEDF,0xFF01,0xFF22,0xFF43,0xFF64,0xFF85,0xFFA5,0xFFC5,
  0xFFE5,0x0004,0x0023,0x0042,0x0061,0x007F,0x009E,0x00BC,
  0x00DA,0x00F7,0x0115,0x0132,0x014E,0x016B,0x0187,0x01A3,
  0x01BF,0x01DA,0x01F5,0x0210,0x022A,0x0245,0x025E,0x0278,
  0x0291,0x02AB,0x02C3,0x02DC,0x02F4,0x030C,0x0323,0x033B,
  0x0352,0x0368,0x037F,0x0395,0x03AB,0x03C0,0x03D5,0x03EA,
  0x03FF,0x0413,0x0427,0x043A,0x044E,0x0461,0x0473,0x0486,
  0x0498,0x04AA,0x04BB,0x04CC,0x04DD,0x04EE,0x04FE,0x050E,
  0x051D,0x052D,0x053C,0x054A,0x0559,0x0567,0x0575,0x0582,
  0x058F,0x059C,0x05A8,0x05B5,0x05C1,0x05CC,0x05D8,0x05E3,
  0x05ED,0x05F8,0x0602,0x060C,0x0615,0x061E,0x0627,0x0630,
  0x0638,0x0640,0x0648,0x0650,0x0657,0x065E,0x0664,0x066B,
  0x0671,0x0676,0x067C,0x0681,0x0686,0x068B,0x068F,0x0693,
  0x0697,0x069A,0x069E,0x06A1,0x06A4,0x06A6,0x06A8,0x06AA,
  0x06AC,0x06AD,0x06AF,0x06B0,0x06B0,0x06B1,0x06B1,0x06B1,
  0x06B1,0x06B0,0x06AF,0x06AE,0x06AD,0x06AC,0x06AA,0x06A8,
  0x06A6,0x06A4,0x06A1,0x069E,0x069B,0x0698,0x0695,0x0691,
  0x068D,0x0689,0x0685,0x0680,0x067C,0x0677,0x0672,0x066C,
  0x0667,0x0661,0x065B,0x0655,0x064F,0x0649,0x0642,0x063C,
  0x0635,0x062E,0x0627,0x061F,0x0618,0x0610,0x0608,0x0600,
  0x05F8,0x05F0,0x05E7,0x05DF,0x05D6,0x05CD,0x05C4,0x05BB,
  0x05B2,0x05A8,0x059F,0x0595,0x058B,0x0581,0x0577,0x056D,
  0x0563,0x0558,0x054E,0x0543,0x0539,0x052E,0x0523,0x0518,
  0x050D,0x0502,0x04F7,0x04EC,0x04E0,0x04D5,0x04C9,0x04BD,
  0x04B2,0x04A6,0x049A,0x048E,0x0482,0x0476,0x046A,0x045E,
  0x0452,0x0446,0x0439,0x042D,0x0421,0x0414,0x0408,0x03FB,
  0x03EF,0x03E2,0x03D5,0x03C9,0x03BC,0x03AF,0x03A3,0x0396,
  0x0389,0x037C,0x036F,0x0363,0x0356,0x0349,0x033C,0x032F,
  0x0322,0x0316,0x0309,0x02FC,0x02EF,0x02E2,0x02D5,0x02C9,
  0x02BC,0x02AF,0x02A2,0x0296,0x0289,0x027C,0x026F,0x0263,
  0x0256,0x0249,0x023D,0x0230,0x0224,0x0217,0x020B,0x01FE,
  0x01F2,0x01E6,0x01D9,0x01CD,0x01C1,0x01B5,0x01A9,0x019D,
  0x0191,0x0185,0x0179,0x016D,0x0161,0x0155,0x014A,0x013E,
  0x0133,0x0127,0x011C,0x0110,0x0105,0x00FA,0x00EF,0x00E4,
  0x00D9,0x00CE,0x00C3,0x00B8,0x00AD,0x00A3,0x0098,0x008D,
  0x0083,0x0079,0x006E,0x0064,0x005A,0x0050,0x0046,0x003C,
  0x0033,0x0029,0x001F,0x0016,0x000C,0x0003,0xFFFB,0xFFF2,
  0xFFE9,0xFFE0,0xFFD7,0xFFCE,0xFFC5,0xFFBD,0xFFB4,0xFFAC,
  0xFFA3,0xFF9B,0xFF93,0xFF8B,0xFF83,0xFF7B,0xFF74,0xFF6C,
  0xFF64,0xFF5D,0xFF56,0xFF4E,0xFF47,0xFF40,0xFF39,0xFF32,
  0xFF2C,0xFF25,0xFF1E,0xFF18,0xFF11,0xFF0B,0xFF05,0xFEFF,
  0xFEF9,0xFEF3,0xFEED,0xFEE8,0xFEE2,0xFEDD,0xFED7,0xFED2,
  0xFECD,0xFEC8,0xFEC3,0xFEBE,0xFEB9,0xFEB4,0xFEB0,0xFEAB,
  0xFEA7,0xFEA3,0xFE9E,0xFE9A,0xFE96,0xFE92,0xFE8F,0xFE8B,
  0xFE87,0xFE84,0xFE80,0xFE7D,0xFE7A,0xFE76,0xFE73,0xFE70,
  0xFE6E,0xFE6B,0xFE68,0xFE65,0xFE63,0xFE60,0xFE5E,0xFE5C,
  0xFE5A,0xFE58,0xFE56,0xFE54,0xFE52,0xFE50,0xFE4F,0xFE4D,
  0xFE4C,0xFE4A,0xFE49,0xFE48,0xFE46,0xFE45,0xFE44,0xFE43,
  0xFE43,0xFE42,0xFE41,0xFE41,0xFE40,0xFE40,0xFE3F,0xFE3F,
  0xFE3F,0xFE3F,0xFE3F,0xFE3F,0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FBD,0xFFBF,0xFFC2,0xFFC5,0xFFC7,
  0xFFC9,0xFFCC,0xFFCE,0xFFD1,0xFFD3,0xFFD5,0xFFD8,0xFFDA,
  0xFFDC,0xFFDF,0xFFE1,0xFFE3,0xFFE5,0xFFE7,0xFFEA,0xFFEC,
  0xFFEE,0xFFF0,0xFFF2,0xFFF4,0xFFF6,0xFFF8,0xFFFA,0xFFFC,
  0xFFFE,0x0000,0x0000,0x0002,0x0004,0x0006,0x0008,0x0009,
  0x000B,0x000D,0x000E,0x0010,0x0011,0x0013,0x0015,0x0016,
  0x0018,0x0019,0x001B,0x001C,0x001D,0x001F,0x0020,0x0021,
  0x0023,0x0024,0x0025,0x0026,0x0028,0x0029,0x002A,0x002B,
  0x002C,0x002D,0x002E,0x002F,0x0030,0x0031,0x0032,0x0033,
  0x0034,0x0035,0x0036,0x0037,0x0038,0x0038,0x0039,0x003A,
  0x003B,0x003B,0x003C,0x003D,0x003E,0x003E,0x003F,0x003F,
  0x0040,0x0040,0x0041,0x0042,0x0042,0x0042,0x0043,0x0043,
  0x0044,0x0044,0x0045,0x0045,0x0045,0x0046,0x0046,0x0046,
  0x0046,0x0047,0x0047,0x0047,0x0047,0x0047,0x0048,0x0048,
  0x0048,0x0048,0x0048,0x0048,0x0048,0x0048,0x0048,0x0048,
  0x0048,0x0048,0x0048,0x0048,0x0048,0x0048,0x0048,0x0048,
  0x0048,0x0048,0x0048,0x0048,0x0048,0x0047,0x0047,0x0047,
  0x0047,0x0047,0x0046,0x0046,0x0046,0x0046,0x0045,0x0045,
  0x0045,0x0045,0x0044,0x0044,0x0044,0x0043,0x0043,0x0043,
  0x0042,0x0042,0x0042,0x0041,0x0041,0x0040,0x0040,0x0040,
  0x003F,0x003F,0x003E,0x003E,0x003E,0x003D,0x003D,0x003C,
  0x003C,0x003B,0x003B,0x003A,0x003A,0x003A,0x0039,0x0039,
  0x0038,0x0038,0x0037,0x0037,0x0036,0x0036,0x0035,0x0035,
  0x0034,0x0034,0x0033,0x0033,0x0032,0x0032,0x0031,0x0030,
  0x0030,0x002F,0x002F,0x002E,0x002E,0x002D,0x002D,0x002C,
  0x002C,0x002B,0x002B,0x002A,0x002A,0x0029,0x0029,0x0028,
  0x0027,0x0027,0x0026,0x0026,0x0025,0x0025,0x0024,0x0024,
  0x0023,0x0023,0x0022,0x0022,0x0021,0x0021,0x0020,0x0020,
  0x001F,0x001F,0x001E,0x001E,0x001D,0x001D,0x001C,0x001C,
  0x001B,0x001B,0x001A,0x001A,0x0019,0x0019,0x0018,0x0018,
  0x0017,0x0017,0x0017,0x0016,0x0016,0x0015,0x0015,0x0014,
  0x0014,0x0014,0x0013,0x0013,0x0012,0x0012,0x0011,0x0011,
  0x0011,0x0010,0x0010,0x000F,0x000F,0x000F,0x000E,0x000E,
  0x000E,0x000D,0x000D,0x000C,0x000C,0x000C,0x000B,0x000B,
  0x000B,0x000A,0x000A,0x000A,0x0009,0x0009,0x0009,0x0009,
  0x0008,0x0008,0x0008,0x0007,0x0007,0x0007,0x0007,0x0006,
  0x0006,0x0006,0x0006,0x0005,0x0005,0x0005,0x0005,0x0004,
  0x0004,0x0004,0x0004,0x0003,0x0003,0x0003,0x0003,0x0003,
  0x0002,0x0002,0x0002,0x0002,0x0002,0x0001,0x0001,0x0001,
  0x0001,0x0001,0x0001,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,
  0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,
  0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,
  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
  0xFF9E,0xFF9E,0xFF9C,0xFF9C,0xFF9A,0xFF99,0xFF98,0xFF97,
  0xFF96,0xFF95,0xFF94,0xFF93,0xFF91,0xFF91,0xFF90,0xFF8F,
  0xFF8D,0xFF8D,0xFF8C,0xFF8B,0xFF89,0xFF89,0xFF88,0xFF87,
  0xFF87,0xFF85,0xFF84,0xFF84,0xFF82,0xFF82,0xFF81,0xFF80,
  0xFF7F,0xFF7F,0xFF7D,0xFF7D,0xFF7C,0xFF7B,0xFF7B,0xFF79,
  0xFF79,0xFF79,0xFF77,0xFF77,0xFF76,0xFF76,0xFF74,0xFF75,
  0xFF73,0xFF73,0xFF72,0xFF72,0xFF71,0xFF70,0xFF70,0xFF6F,
  0xFF6F,0xFF6E,0xFF6E,0xFF6D,0xFF6C,0xFF6C,0xFF6C,0xFF6B,
  0xFF6B,0xFF6A,0xFF6A,0xFF69,0xFF69,0xFF68,0xFF69,0xFF67,
  0xFF68,0xFF67,0xFF66,0xFF67,0xFF66,0xFF66,0xFF65,0xFF65,
  0xFF65,0xFF65,0xFF64,0xFF64,0xFF64,0xFF64,0xFF63,0xFF64,
  0xFF63,0xFF63,0xFF63,0xFF63,0xFF62,0xFF63,0xFF62,0xFF62,
  0xFF63,0xFF62,0xFF62,0xFF62,0xFF62,0xFF62,0xFF62,0xFF62,
  0xFF62,0xFF62,0xFF62,0xFF63,0xFF62,0xFF62,0xFF63,0xFF62,
  0xFF63,0xFF62,0xFF63,0xFF63,0xFF63,0xFF64,0xFF63,0xFF64,
  0xFF64,0xFF64,0xFF64,0xFF65,0xFF65,0xFF65,0xFF65,0xFF66,
  0xFF65,0xFF67,0xFF66,0xFF67,0xFF67,0xFF68,0xFF67,0xFF69,
  0xFF68,0xFF69,0xFF6A,0xFF69,0xFF6A,0xFF6B,0xFF6B,0xFF6B,
  0xFF6C,0xFF6D,0xFF6C,0xFF6E,0xFF6E,0xFF6E,0xFF6F,0xFF6F,
  0xFF70,0xFF70,0xFF71,0xFF71,0xFF73,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FFF1,
  0xFFF2,0xFFF2,0xFFF3,0xFFF4,0xFFF5,0xFFF6,0xFFF6,0xFFF7,
  0xFFF8,0xFFF9,0xFFFA,0xFFFA,0xFFFB,0xFFFC,0xFFFC,0xFFFE,
  0xFFFE,0xFFFE,0x0000,0x0000,0x0001,0x0002,0x0002,0x0003,
  0x0004,0x0004,0x0005,0x0006,0x0006,0x0007,0x0008,0x0009,
  0x0009,0x0009,0x000B,0x000B,0x000B,0x000C,0x000D,0x000D,
  0x000E,0x000F,0x000F,0x0010,0x0010,0x0011,0x0011,0x0012,
  0x0013,0x0013,0x0013,0x0014,0x0015,0x0015,0x0015,0x0016,
  0x0017,0x0017,0x0018,0x0017,0x0019,0x0019,0x0019,0x001A,
  0x001A,0x001B,0x001B,0x001B,0x001C,0x001C,0x001D,0x001D,
  0x001E,0x001D,0x001E,0x001F,0x001F,0x001F,0x0020,0x0020,
  0x0020,0x0020,0x0021,0x0021,0x0022,0x0021,0x0022,0x0023,
  0x0022,0x0023,0x0023,0x0023,0x0024,0x0024,0x0024,0x0024,
  0x0025,0x0024,0x0025,0x0025,0x0026,0x0025,0x0026,0x0025,
  0x0026,0x0027,0x0026,0x0026,0x0027,0x0027,0x0026,0x0027,
  0x0027,0x0028,0x0027,0x0027,0x0028,0x0027,0x0028,0x0028,
  0x0027,0x0028,0x0028,0x0028,0x0028,0x0028,0x0028,0x0028,
  0x0028,0x0028,0x0028,0x0029,0x0028,0x0028,0x0028,0x0028,
  0x0028,0x0028,0x0028,0x0028,0x0028,0x0028,0x0027,0x0028,
  0x0028,0x0027,0x0028,0x0027,0x0028,0x0027,0x0027,0x0027,
  0x0027,0x0027,0x0027,0x0027,0x0026,0x0026,0x0027,0x0026,
  0x0026,0x0026,0x0025,0x0026,0x0025,0x0026,0x0025,0x0024,
  0x0025,0x0025,0x0024,0x0024,0x0024,0x0024,0x0024,0x0023,
  0x0023,0x0024,0x0022,0x0023,0x0022,0x0023,0x0022,0x0021,
  0x0022,0x0021,0x0021,0x0021,0x0021,0x0020,0x0020,0x0020,
  0x001F,0x001F,0x001F,0x001F,0x001E,0x001F,0x001E,0x001E,
  0x001D,0x001E,0x001D,0x001C,0x001D,0x001C,0x001C,0x001C,
  0x001B,0x001B,0x001B,0x001A,0x001B,0x0019,0x001A,0x0019,
  0x001A,0x0018,0x0019,0x0018,0x0018,0x0017,0x0018,0x0017,
  0x0016,0x0017,0x0016,0x0016,0x0015,0x0015,0x0015,0x0015,
  0x0014,0x0014,0x0013,0x0014,0x0013,0x0012,0x0013,0x0012,
  0x0012,0x0011,0x0011,0x0011,0x0011,0x0010,0x0010,0x000F,
  0x0010,0x000F,0x000E,0x000F,0x000E,0x000E,0x000D,0x000D,
  0x000D,0x000C,0x000D,0x000C,0x000B,0x000C,0x000B,0x000A,
  0x000B,0x000A,0x000A,0x0009,0x0009,0x0009,0x0009,0x0008,
  0x0008,0x0008,0x0008,0x0007,0x0007,0x0006,0x0007,0x0006,
  0x0005,0x0006,0x0005,0x0005,0x0005,0x0004,0x0004,0x0004,
  0x0003,0x0004,0x0003,0x0003,0x0002,0x0002,0x0002,0x0002,
  0x0001,0x0002,0x0001,0x0000,0x0001,0x0000,0x0000,0x0000,
  0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xFFFE,0xFFFE,
  0xFFFE,0xFFFD,0xFFFD,0xFFFD,0xFFFD,0xFFFD,0xFFFC,0xFFFC,
  0xFFFC,0xFFFC,0xFFFB,0xFFFC,0xFFFB,0xFFFB,0xFFFA,0xFFFB,
  0xFFFA,0xFFFA,0xFFFA,0xFFFA,0xFFFA,0xFFF9,0xFFFA,0xFFF9,
  0xFFF9,0xFFF9,0xFFF8,0xFFF9,0xFFF8,0xFFF8,0xFFF8,0xFFF8,
  0xFFF8,0xFFF7,0xFFF8,0xFFF7,0xFFF7,0xFFF7,0xFFF7,0xFFF7,
  0xFFF6,0xFFF7,0xFFF6,0xFFF6,0xFFF6,0xFFF6,0xFFF6,0xFFF6,
  0xF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,0xFFF9,0xFFFA,
  0xFFF9,0xFFF9,0xFFFA,0xFFF9,0xFFFA,0xFFFA,0xFFFA,0xFFFA,
  0xFFFA,0xFFFA,0xFFFB,0xFFFA,0xFFFB,0xFFFA,0xFFFB,0xFFFB,
  0xFFFB,0xFFFB,0xFFFB,0xFFFB,0xFFFB,0xFFFC,0xFFFB,0xFFFC,
  0xFFFC,0xFFFB,0xFFFC,0xFFFC,0xFFFC,0xFFFD,0xFFFC,0xFFFC,
  0xFFFD,0xFFFC,0xFFFD,0xFFFD,0xFFFC,0xFFFD,0xFFFD,0xFFFE,
  0xFFFD,0xFFFD,0xFFFD,0xFFFE,0xFFFD,0xFFFE,0xFFFE,0xFFFE,
  0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFF,0xFFFE,0xFFFF,
  0xFFFE,0xFFFF,0xFFFF,0xFFFE,0xFFFF,0xFFFF,0xFFFF,0x0000,
  0xFFFF,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0001,0x0000,0x0001,0x0000,0x0001,0x0001,0x0001,0x0001,
  0x0000,0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,
  0x0002,0x0001,0x0002,0x0001,0x0002,0x0001,0x0002,0x0002,
  0x0002,0x0001,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
  0x0002,0x0002,0x0003,0x0002,0x0002,0x0003,0x0002,0x0002,
  0x0003,0x0002,0x0003,0x0002,0x0003,0x0002,0x0003,0x0003,
  0x0002,0x0003,0x0003,0x0003,0x0002,0x0003,0x0003,0x0003,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,
  0x0004,0x0003,0x0003,0x0003,0x0003,0x0004,0x0003,0x0003,
  0x0003,0x0004,0x0003,0x0003,0x0003,0x0004,0x0003,0x0003,
  0x0003,0x0004,0x0003,0x0003,0x0003,0x0004,0x0003,0x0003,
  0x0003,0x0004,0x0003,0x0003,0x0003,0x0004,0x0003,0x0003,
  0x0003,0x0004,0x0003,0x0003,0x0003,0x0003,0x0003,0x0004,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0004,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0002,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0002,
  0x0003,0x0003,0x0003,0x0002,0x0003,0x0003,0x0002,0x0003,
  0x0003,0x0002,0x0003,0x0002,0x0003,0x0003,0x0002,0x0002,
  0x0003,0x0002,0x0003,0x0002,0x0002,0x0003,0x0002,0x0002,
  0x0003,0x0002,0x0002,0x0002,0x0002,0x0003,0x0002,0x0002,
  0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
  0x0002,0x0000,0x0002,0x0002,0x0002,0x0002,0x0001,0x0002,
  0x0002,0x0001,0x0002,0x0001,0x0002,0x0002,0x0001,0x0002,
  0x0001,0x0002,0x0001,0x0001,0x0002,0x0001,0x0001,0x0002,
  0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,0x0001,
  0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
  0x0001,0x0001,0x0001,0x0001,0x0000,0x0001,0x0001,0x0001,
  0x0000,0x0001,0x0001,0x0001,0x0000,0x0001,0x0000,0x0001,
  0x0000,0x0001,0x0001,0x0000,0x0000,0x0001,0x0000,0x0001,
  0x0000,0x0001,0x0000,0x0000,0x0001,0x0000,0x0000,0x0000,
  0x0001,0x0000,0x0000,0x0000,0x0000,0x0001,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,
  0x0000,0xFFFF,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,
  0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,
  0x0000,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0xFFFF,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0x0000,
  0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0xFFFF,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0xFFFF,0x0000,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0xFFFF,0x0000,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0x0000,0xFFFF,
  0x0000,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xFFFF,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0001,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,
  0xFFFF,0xFFFE,0xFFFC,0xFFFB,0xFFFA,0xFFF8,0xFFF6,0xFFF6,
  0xFFF3,0xFFF3,0xFFF0,0xFFF0,0xFFEE,0xFFEC,0xFFEB,0xFFEA,
  0xFFE8,0xFFE7,0xFFE5,0xFFE4,0xFFE2,0xFFE1,0xFFE0,0xFFDE,
  0xFFDD,0xFFDB,0xFFDA,0xFFD9,0xFFD7,0xFFD6,0xFFD4,0xFFD3,
  0xFFD2,0xFFD0,0xFFCF,0xFFCD,0xFFCC,0xFFCB,0xFFC9,0xFFC8,
  0xFFC7,0xFFC5,0xFFC4,0xFFC3,0xFFC1,0xFFC0,0xFFBF,0xFFBD,
  0xFFBC,0xFFBB,0xFFB9,0xFFB9,0xFFB6,0xFFB6,0xFFB4,0xFFB3,
  0xFFB2,0xFFB1,0xFFAF,0xFFAE,0xFFAD,0xFFAC,0xFFAA,0xFFA9,
  0xFFA8,0xFFA7,0xFFA6,0xFFA4,0xFFA4,0xFFA2,0xFFA1,0xFFA0,
  0xFF9E,0xFF9E,0xFF9C,0xFF9C,0xFF9A,0xFF99,0xFF98,0xFF97,
  0xFF96,0xFF95,0xFF94,0xFF93,0xFF91,0xFF91,0xFF90,0xFF8F,
  0xFF8D,0xFF8D,0xFF8C,0xFF8B,0xFF89,0xFF89,0xFF88,0xFF87,
  0xFF87,0xFF85,0xFF84,0xFF84,0xFF82,0xFF82,0xFF81,0xFF80,
  0xFF7F,0xFF7F,0xFF7D,0xFF7D,0xFF7C,0xFF7B,0xFF7B,0xFF79,
  0xFF79,0xFF79,0xFF77,0xFF77,0xFF76,0xFF76,0xFF74,0xFF75,
  0xFF73,0xFF73,0xFF72,0xFF72,0xFF71,0xFF70,0xFF70,0xFF6F,
  0xFF6F,0xFF6E,0xFF6E,0xFF6D,0xFF6C,0xFF6C,0xFF6C,0xFF6B,
  0xFF6B,0xFF6A,0xFF6A,0xFF69,0xFF69,0xFF68,0xFF69,0xFF67,
  0xFF68,0xFF67,0xFF66,0xFF67,0xFF66,0xFF66,0xFF65,0xFF65,
  0xFF65,0xFF65,0xFF64,0xFF64,0xFF64,0xFF64,0xFF63,0xFF64,
  0xFF63,0xFF63,0xFF63,0xFF63,0xFF62,0xFF63,0xFF62,0xFF62,
  0xFF63,0xFF62,0xFF62,0xFF62,0xFF62,0xFF62,0xFF62,0xFF62,
  0xFF62,0xFF62,0xFF62,0xFF63,0xFF62,0xFF62,0xFF63,0xFF62,
  0xFF63,0xFF62,0xFF63,0xFF63,0xFF63,0xFF64,0xFF63,0xFF64,
  0xFF64,0xFF64,0xFF64,0xFF65,0xFF65,0xFF65,0xFF65,0xFF66,
  0xFF65,0xFF67,0xFF66,0xFF67,0x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0xFFDC,0xFFDE,0xFFDF,0xFFDF,0xFFE1,0xFFE1,0xFFE2,0xFFE3,
  0xFFE4,0xFFE5,0xFFE6,0xFFE7,0xFFE7,0xFFE9,0xFFE9,0xFFEA,
  0xFFEB,0xFFEC,0xFFEC,0xFFEE,0xFFEE,0xFFEF,0xFFF0,0xFFF1,
  0xFFF2,0xFFF2,0xFFF3,0xFFF4,0xFFF5,0xFFF6,0xFFF6,0xFFF7,
  0xFFF8,0xFFF9,0xFFFA,0xFFFA,0xFFFB,0xFFFC,0xFFFC,0xFFFE,
  0xFFFE,0xFFFE,0x0000,0x0000,0x0001,0x0002,0x0002,0x0003,
  0x0004,0x0004,0x0005,0x0006,0x0006,0x0007,0x0008,0x0009,
  0x0009,0x0009,0x000B,0x000B,0x000B,0x000C,0x000D,0x000D,
  0x000E,0x000F,0x000F,0x0010,0x0010,0x0011,0x0011,0x0012,
  0x0013,0x0013,0x0013,0x0014,0x0015,0x0015,0x0015,0x0016,
  0x0017,0x0017,0x0018,0x0017,0x0019,0x0019,0x0019,0x001A,
  0x001A,0x001B,0x001B,0x001B,0x001C,0x001C,0x001D,0x001D,
  0x001E,0x001D,0x001E,0x001F,0x001F,0x001F,0x0020,0x0020,
  0x0020,0x0020,0x0021,0x0021,0x0022,0x0021,0x0022,0x0023,
  0x0022,0x0023,0x0023,0x0023,0x0024,0x0024,0x0024,0x0024,
  0x0025,0x0024,0x0025,0x0025,0x0026,0x0025,0x0026,0x0025,
  0x0026,0x0027,0x0026,0x0026,0x0027,0x0027,0x0026,0x0027,
  0x0027,0x0028,0x0027,0x0027,0x0028,0x0027,0x0028,0x0028,
  0x0027,0x0028,0x0028,0x0028,0x0028,0x0028,0x0028,0x0028,
  0x0028,0x0028,0x0028,0x0029,0x0028,0x0028,0x0028,0x0028,
  0x0028,0x0028,0x0028,0x0028,0x0028,0x0028,0x0027,0x0028,
  0x0028,0x0027,0x0028,0x0027,0x0028,0x0027,0x0027,0x0027,
  0x0027,0x0027,0x0027,0x0027,0x0026,0x0026,0x0027,0x0026,
  0x0026,0x0026,0x0025,0x0026,0x0025,0x0026,0x0025,0x0024,
  0x0025,0x0025,0x0024,0x0024,0x0024,0x0024,0x0024,0x0023,
  0x0023,0x0024,0x0022,0x0023,0x0022,0x0023,0x0022,0x0021,
  0x0022,0x0021,0x0021,0x0021,0x0021,0x0020,0x0020,0x0020,
  0x001F,0x001F,0x001F,0x001F,0x001E,0x001F,0x001E,0x001E,
  0x001D,0x001E,0x001D,0x001C,0x001D,0x001C,0x001C,0x001C,
  0x001B,0x001B,0x001B,0x001A,0x001B,0x0019,0x001A,0x0019,
  0x001A,0x0018,0x0019,0x0018,0x0018,0x0017,0x0018,0x0017,
  0x0016,0x0017,0x0016,0x0016,0x0015,0x0015,0x0015,0x0015,
  0x0014,0x0014,0x0013,0x0014,0x0013,0x0012,0x0013,0x0012,
  0x0012,0x0011,0x0011,0x0011,0x0011,0x0010,0x0010,0x000F,
  0x0010,0x000F,0x000E,0x000F,0x000E,0x000E,0x000D,0x000D,
  0x000D,0x000C,0x000D,0x000C,0x000B,0x000C,0x000B,0x000A,
  0x000B,0x000A,0x000A,0x0009,0x0009,0x0009,0x0009,0x0008,
  0x0008,0x0008,0x0008,0x0007,0x0007,0x0006,0x0007,0x0006,
  0x0005,0x0006,0x0005,0x0005,0x0005,0x0004,0x0004,0x0004,
  0x0003,0x0004,0x0003,0x0003,0x0002,0x0002,0x0002,0x0002,
  0x0001,0x0002,0x0001,0x0000,0x0001,0x0000,0x0000,0x0000,
  0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xFFFE,0xFFFE,
  0xFFFE,0xFFFD,0xFFFD,0xFFFD,0xFFFD,0xFFFD,0xFFFC,0xFFFC,
  0xFFFC,0xFFFC,0xFFFB,0xFFFC,0xFFFB,0xFFFB,0xFFFA,0xFFFB,
  0xFFFA,0xFFFA,0xFFFA,0xFFFA,0xFFFA,0xFFF9,0xFFFA,0xFFF9,
  0xFFF9,0xF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,0xFFF7,
  0xFFF7,0xFFF7,0xFFF7,0xFFF7,0xFFF8,0xFFF7,0xFFF8,0xFFF7,
  0xFFF8,0xFFF8,0xFFF8,0xFFF8,0xFFF8,0xFFF9,0xFFF8,0xFFF8,
  0xFFF9,0xFFF9,0xFFF8,0xFFF9,0xFFF9,0xFFF9,0xFFF9,0xFFFA,
  0xFFF9,0xFFF9,0xFFFA,0xFFF9,0xFFFA,0xFFFA,0xFFFA,0xFFFA,
  0xFFFA,0xFFFA,0xFFFB,0xFFFA,0xFFFB,0xFFFA,0xFFFB,0xFFFB,
  0xFFFB,0xFFFB,0xFFFB,0xFFFB,0xFFFB,0xFFFC,0xFFFB,0xFFFC,
  0xFFFC,0xFFFB,0xFFFC,0xFFFC,0xFFFC,0xFFFD,0xFFFC,0xFFFC,
  0xFFFD,0xFFFC,0xFFFD,0xFFFD,0xFFFC,0xFFFD,0xFFFD,0xFFFE,
  0xFFFD,0xFFFD,0xFFFD,0xFFFE,0xFFFD,0xFFFE,0xFFFE,0xFFFE,
  0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFE,0xFFFF,0xFFFE,0xFFFF,
  0xFFFE,0xFFFF,0xFFFF,0xFFFE,0xFFFF,0xFFFF,0xFFFF,0x0000,
  0xFFFF,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0001,0x0000,0x0001,0x0000,0x0001,0x0001,0x0001,0x0001,
  0x0000,0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,
  0x0002,0x0001,0x0002,0x0001,0x0002,0x0001,0x0002,0x0002,
  0x0002,0x0001,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
  0x0002,0x0002,0x0003,0x0002,0x0002,0x0003,0x0002,0x0002,
  0x0003,0x0002,0x0003,0x0002,0x0003,0x0002,0x0003,0x0003,
  0x0002,0x0003,0x0003,0x0003,0x0002,0x0003,0x0003,0x0003,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,
  0x0004,0x0003,0x0003,0x0003,0x0003,0x0004,0x0003,0x0003,
  0x0003,0x0004,0x0003,0x0003,0x0003,0x0004,0x0003,0x0003,
  0x0003,0x0004,0x0003,0x0003,0x0003,0x0004,0x0003,0x0003,
  0x0003,0x0004,0x0003,0x0003,0x0003,0x0004,0x0003,0x0003,
  0x0003,0x0004,0x0003,0x0003,0x0003,0x0003,0x0003,0x0004,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0004,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0002,
  0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0002,
  0x0003,0x0003,0x0003,0x0002,0x0003,0x0003,0x0002,0x0003,
  0x0003,0x0002,0x0003,0x0002,0x0003,0x0003,0x0002,0x0002,
  0x0003,0x0002,0x0003,0x0002,0x0002,0x0003,0x0002,0x0002,
  0x0003,0x0002,0x0002,0x0002,0x0002,0x0003,0x0002,0x0002,
  0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
  0x0002,0x0000,0x0002,0x0002,0x0002,0x0002,0x0001,0x0002,
  0x0002,0x0001,0x0002,0x0001,0x0002,0x0002,0x0001,0x0002,
  0x0001,0x0002,0x0001,0x0001,0x0002,0x0001,0x0001,0x0002,
  0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,0x0001,
  0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
  0x0001,0x0001,0x0001,0x0001,0x0000,0x0001,0x0001,0x0001,
  0x0000,0x0001,0x0001,0x0001,0x0000,0x0001,0x0000,0x0001,
  0x0000,0x0001,0x0001,0x0000,0x0000,0x0001,0x0000,0x0001,
  0x0000,0x0001,0x0000,0x0000,0x0001,0x0000,0x0000,0x0000,
  0x0001,0x0000,0x0000,0x0000,0x0000,0x0001,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,
  0x0000,0xFFFF,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,
  0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,
  0x0000,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0xFFFF,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,
  0x0000,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,
  0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0x0000,
  0xFFFF,0x0000,0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0x0000,
  0xFFFF,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0xFFFF,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0xFFFF,0x0000,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0xFFFF,0x0000,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0x0000,0xFFFF,
  0x0000,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xFFFF,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0001,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001
};

/*############################################################################*/

/*------------------*/
/*  CONVERSION API  */
/*------------------*/                                              /* [7301] */
                                                           /* Convert to 8kHz */
signed short filter_resample_xto8 (const signed short *in, signed short *out, \
                                   unsigned char rate)
{
  unsigned short dhb,lpscl,nx,x;
  unsigned char xoff,ipol;
  const signed short *p;
  unsigned long s,t;
  signed short h;
  signed long y;

  /* Check Parameter */
  if ((in == NULL) || (out == NULL))
    return E_FILTER_NULLPTR;
  if (rate >= K_FILTER_SAMPLERATES)
    return E_FILTER_SAMPLERATE;

  /* Convert data */
  if (rate == K_FILTER_SAMPLERATE_8000)
    memcpy (out, in, K_FILTER_CHUNKSIZE_8K << 1);
  else
  {
    nx    = filter_chunklen   [rate];
    xoff  = filter__xto8_xoff [rate - 1];
    dhb   = filter__xto8_dhb  [rate - 1];
    lpscl = filter__xto8_lpscl[rate - 1];
    ipol  = filter__xto8_ipol [rate - 1];
    s  = ((unsigned long)xoff << K_FILTER_NP) * K_FILTER_CHUNKSIZE_8K;
    in -= xoff;
    for (x=0; x<K_FILTER_CHUNKSIZE_8K; x++)
    {
      t = s / K_FILTER_CHUNKSIZE_8K;
      p = in + (t >> K_FILTER_NP);
      h = (signed short)(t & K_FILTER_PMASK);
      y = filter__convert_updown (p, h, -1, dhb, ipol);
      h = (signed short)((0L - t) & K_FILTER_PMASK);
      y += filter__convert_updown (p + 1, h, 1, dhb, ipol);
      y >>= K_FILTER_NHG;
      y *= lpscl;
      y += 1 << (K_FILTER_NLPSCL - 1);
      y >>= K_FILTER_NLPSCL;
      if (y > 32767L)
        y = 32767L;
      else if (y < -32768L)
        y = -32768L;
      *out++ = (signed short)y;
      s += (unsigned long)nx << K_FILTER_NP;
    }
  }
  return 0;
}
                                                                    /* [7302] */
                                                         /* Convert from 8kHz */
signed short filter_resample_8tox (const signed short *in, signed short *out, \
                                   unsigned char rate)
{
  unsigned short lpscl,ny,x;
  unsigned char xoff,ipol;
  const signed short *p;
  unsigned long s,t;
  signed short h;
  signed long y;

  /* Check Parameter */
  if ((in == NULL) || (out == NULL))
    return E_FILTER_NULLPTR;
  if (rate >= K_FILTER_SAMPLERATES)
    return E_FILTER_SAMPLERATE;

  /* Convert data */
  if (rate == K_FILTER_SAMPLERATE_8000)
    memcpy (out, in, K_FILTER_CHUNKSIZE_8K << 1);
  else
  {
    ny    = filter_chunklen   [rate];
    xoff  = filter__8tox_xoff [rate - 1];
    lpscl = filter__8tox_lpscl[rate - 1];
    ipol  = filter__8tox_ipol [rate - 1];
    s  = ((unsigned long)xoff << K_FILTER_NP) * ny;
    in -= xoff;
    for (x=0; x<ny; x++)
    {
      t = s / ny;
      p = in + (t >> K_FILTER_NP);
      h = (signed short)(t & K_FILTER_PMASK);
      y = filter__convert_up (p, h, -1, ipol);
      h = (signed short)((0L - t) & K_FILTER_PMASK);
      y += filter__convert_up (p + 1, h, 1, ipol);
      y >>= K_FILTER_NHG;
      y *= lpscl;
      y += 1 << (K_FILTER_NLPSCL - 1);
      y >>= K_FILTER_NLPSCL;
      if (y > 32767L)
        y = 32767L;
      else if (y < -32768L)
        y = -32768L;
      *out++ = (signed short)y;
      s += K_FILTER_CHUNKSIZE_8K << K_FILTER_NP;
    }
  }
  return 0;
}

/*----*/

static signed long filter__convert_updown (const signed short *p,            \
                                           signed short ph, signed char inc, \
                                           unsigned long dhb,                \
                                           unsigned char ipol)
{
  const signed short *e,*f,*g;
  unsigned long h;
  signed long x,y;
  signed short n;

  x = 0L;
  e = filter__imptbl1 + K_FILTER_IMPTBL1LEN;
  h = (ph * dhb) >> K_FILTER_NP;
  if (inc == 1)            /* If doing right wing drop extra     */
  {                        /* coeff, so when Ph is 0.5, we don't */
    e--;                   /* do too many mult's                 */
    if (ph == 0)           /* If phase is zero we've skipped the */
      h += dhb;            /* first sample, skip in Imp[]/ImpD[] */
  }
  if (ipol)
    while (42)
    {
      f = filter__imptbl1 + (h >> K_FILTER_NA);
      if (f >= e)
        break;
      y = *f;                    /* Get IR sample   */
      /* get interp (lower Na) bits from diff table */
      g = filter__imptbl2 + (h >> K_FILTER_NA);
      /* n is logically between 0 and 1 */
      n = (signed short)(h & K_FILTER_AMASK);
      /* y is now interp'd filter coeff */
      y += (((signed long)*g) * n) >> K_FILTER_NA;
      y *= *p;                   /* Mult coeff by input sample */
      y += 1 << (K_FILTER_NHXN - 1);    /* Round and scale val */
      y >>= K_FILTER_NHXN;       /* Leave some guard bits, but come back some */
      x += y;                    /* The filter output */
      h += dhb;                  /* IR step */
      p += inc;                  /* Input signal step. NO CHECK ON BOUNDS */
    }
  else
    while (42)
    {
      f = filter__imptbl1 + (h >> K_FILTER_NA);
      if (f >= e)
        break;
      y = *f;                    /* Get IR sample */
      y *= *p;                   /* Mult coeff by input sample */
      y += 1 << (K_FILTER_NHXN - 1);    /* Round and scale val */
      y >>= K_FILTER_NHXN;       /* Leave some guard bits, but come back some */
      x += y;                    /* The filter output */
      h += dhb;                  /* IR step */
      p += inc;                  /* Input signal step. NO CHECK ON BOUNDS */
    }
  return x;
}


static signed long filter__convert_up (const signed short *p, signed short ph, \
                                       signed char inc, unsigned char ipol)
{
  const signed short *e,*f,*g;
  signed long x,y;
  signed short n;

  x = 0L;
  e = filter__imptbl1 + K_FILTER_IMPTBL1LEN;
  f = filter__imptbl1 + (ph >> K_FILTER_NA);
  g = NULL;
  if (ipol)
  {
    g = filter__imptbl2 + (ph >> K_FILTER_NA);
    n = ph & K_FILTER_AMASK;
  }
  if (inc > 0)             /* If doing right wing drop extra     */
  {                        /* coeff, so when Ph is 0.5, we don't */
    e--;                   /* do too many mult's                 */
    if (ph == 0)           /* If phase is zero we've skipped the */
    {                      /* first sample, skip in Imp[]/ImpD[] */
      f += K_FILTER_NPC;
      g += K_FILTER_NPC;
    }
  }
  if (ipol)
    while (f < e)
    {                            /* Get filter coeff */
      y = *f;                    /* y is now interp'd filter coeff */
      y += (((signed long)*g) * n) >> K_FILTER_NA;
      g += K_FILTER_NPC;         /* Filter coeff differences step */
      y *= *p;                   /* Mult coeff by input sample */
      y += (1 << (K_FILTER_NHXN - 1));  /* Round and scale val */
      y >>= K_FILTER_NHXN;       /* Leave some guard bits, but come back some */
      x += y;                    /* The filter output */
      f += K_FILTER_NPC;         /* Filter coeff step */
      p += inc;                  /* Input signal step. NO CHECK ON BOUNDS */
    }
  else
    while (f < e)
    {
      y = *f;                    /* Get filter coeff */
      y *= *p;                   /* Mult coeff by input sample */
      y += (1 << (K_FILTER_NHXN - 1));  /* Round and scale val */
      y >>= K_FILTER_NHXN;       /* Leave some guard bits, but come back some */
      x += y;                    /* The filter output */
      f += K_FILTER_NPC;         /* Filter coeff step */
      p += inc;                  /* Input signal step. NO CHECK ON BOUNDS */
    }
  return x;
}


/*** EOF ***/
